package com.ljy.tkuser.controller;


import com.ljy.tkuser.service.OssServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

@RestController
@RequestMapping("eduoss/fileoss")
@CrossOrigin
public class OssController {
    @Autowired
    private OssServices ossServices;
    @PostMapping("uploadOssFile")
    public HashMap<String,Object> uploadOssFile(@RequestParam MultipartFile file){
        HashMap<String,Object> map =new HashMap<String,Object>();
        String url = null;
        try {
            url = ossServices.uploadFileAvatar(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        map.put("url",url);
        return map;
    }

    @PostMapping("uploadOssFiles")
    public HashMap<String,Object> uploadOssFiles(@RequestParam MultipartFile[] files){
        HashMap<String,Object> map =new HashMap<String,Object>();
        ArrayList<String> listUrl= new ArrayList<String>();
        try {
            listUrl = ossServices.uploadFileAvatars(files);
        } catch (IOException e) {
            e.printStackTrace();
        }
        map.put("url",listUrl);
        return map;
    }
}
